﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MM.Common.DBBase;

namespace MM.Common.Base
{
    public static class Log
    {
        // Methods
        public static void WriteError(string objectname, string eventname, string info)
        {
            SystemInfo.DbData.TransactionRollback();
            string commandtext = "INSERT INTO MXHLY_SYS_ERROR ( EMP_ID, COMPUTER_CODE, SYSTEM_CODE,  ERROR_OBJECT,  ERROR_EVENT,  ERROR_TEXT)                 VALUES(:emp_id, :node, :system_code, :eobject     , :eevent     , :info      ) ";
            DataParamCol parms = new DataParamCol();
            parms.AddBatch(new object[] { "emp_id", SystemInfo.OperId, "node", SystemInfo.ComputerID, "system_code", SystemInfo.SystemCode, "eobject", objectname, "eevent", eventname, "info", info });
            try
            {
                SystemInfo.DbData.ExecuteSql(commandtext, parms);
            }
            catch
            {
            }
        }

        public static void WriteLogBtnInfo(string info)
        {
            WriteRunInfo("B", info);
        }

        public static void WriteLogSysInfo(string info)
        {
            WriteRunInfo("S", info);
        }

        public static void WriteLogWinInfo(string info)
        {
            WriteRunInfo("W", info);
        }

        public static void WriteRunInfo(string type, string info)
        {
            try
            {
                string commandtext = "INSERT INTO MXHLY_SYS_LOG (EMP_ID, TYPE ,COMPUTER_CODE ,INFO) VALUES (:userid, :type ,:node ,:info)";
                DataParamCol parms = new DataParamCol();
                parms.AddBatch(new object[] { "userid", SystemInfo.OperId, "type", type, "node", SystemInfo.ComputerID, "info", info });
                SystemInfo.DbData.ExecuteSql(commandtext, parms);
            }
            catch
            {
            }
        }
    }
}
